import Mock from 'mockjs';
function paramToObj(url){
    const search = url.split('?')[1];
    if(!search){
        return {};
    }
    let params = {};
    search.split('&').forEach(item=>{
        item = item.split('=');
        let _key = item[0];
        let _value = item[1];
        params[_key] = _value;
    })
    return params;
}
export const getModelList = function (option) {
    console.log('option',option.url)
    // console.log(Mock.mock(option.url))
    let { pageNum } = paramToObj(option.url);
    const modelList = Mock.mock({
        'code': 200,
        'message': 'ok',
        'data': {
            'total': 100,
            'list|10': [{
                "ontologyAllId|+1":1,
                "createUserId":'admin',
                "ontologyAllName":'武器装备本体111111',
                "createTime":'2021-01-01',
                "updateUserId":'admin1',
                "updateTime":'2021-01-11',
                "ontologyAllDescribe":'主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理',
                "ontologyAllState":0
            }],
            "pageNum":pageNum,
            "pageSize":10
        }
    })
    return modelList;
}
export const createOntology = {
    'code': 200,
    'message': 'ok',
    'data':124
}
export const nodeDetail = {
    'code': 200,
    'message': 'ok',
    'data':{
        id:'123_1',
        name:'歼击机',
        parentName:'测试1_1',
        parentIds:['123','123_1'],
        // parentId:'123_1',
        imgUrl:'',
        'property|5':[{
            propertyName:'长度',
            propertyType:'数值（米）',
            // propertyBind:'无约束'
        }]
    }
}
const parentNodesSearch = {
    'code': 200,
    'message': 'ok',
    'data':[
        {
            "value": "123_1",
            "label": "测试1_1",
            "parentId": "123",
        },
        {
            "value": "123_1_1",
            "label": "测试1_1_1",
            "parentId": "123_1",
        },
    ]
}
const parentNodesDefatul = {
    'code': 200,
    'message': 'ok',
    'data':[
        {
            "value": "123",
            "label": "航空飞行器",
            "parentId": null,
            "children": [
                {
                    "value": "123_1",
                    "label": "测试1_1",
                    "parentId": "123",
                    "children": [
                        {
                            "value": "123_1_1",
                            "label": "测试1_1_1",
                            "parentId": "123_1",
                        }
                    ]
                },
                {
                    "value": "123_2",
                    "label": "测试1_2",
                    "parentId": "123",
                    "children": [
                        {
                            "value": "123_2_1",
                            "label": "测试1_2_1",
                            "parentId": "123_2",
                        }
                    ]
                }
            ]
        }
     
    ]
}
export function getParentNodes(option){
    const { keyword } = paramToObj(option.url);
    console.log('keyword',keyword)
    if(keyword){
        return parentNodesSearch;
    }else{
        return parentNodesDefatul;
    }
}
// export const saveOntology = {
//     'code': 200,
//     'message': 'ok',
//     'data':null
// }
export function saveOntology(){
    let random = Math.random();
    if(random > 0.5){
        return {
            'code': 200,
            'message': 'ok!',
            'data':123
        }
    }else if(random <= 0.5){
        return {
            'code': 10001,
            'message': '该节点已存在',
            'data':123
        }
    }
}
export function deleteOntology(option){
    const { ontologyAllId } = JSON.parse(option.body);
    let random = Math.random();
    if(random > 0.3 && random < 0.8){
        return {
            'code': 200,
            'message': '删除成功!',
            'data':123
        }
    }else if(random < 0.3){
        return {
            'code': 10004,
            'message': '该节点下还有子节点，不能删除!',
            'data':123
        }
    }else {
        return {
            'code': 10003,
            'message': '该节点不存在！',
            'data':123
        }
    }
}

export const parentProperty = {
    'code': 200,
    'message': 'ok',
    'data|3':[
        {
            propertyName:'长度',
            propertyType:'数值（米）'
        }
    ]
}

export const edgeDetail = {
    'code': 200,
    'message': 'ok',
    'data':{
        id:344,
        name:'测试线',
        sourceName:'d',
        targetName:'e',
        type:'one-way',
        'property|3':[
            {
                propertyName:'长度',
                propertyType:'数值（米）'
            }
        ]
    }
}
export function getEdgeDetail(option){
    console.log(option)
    let data = paramToObj(option.url);
    if(data.id){
        return edgeDetail;
    }
    let name = data.relationName;
    let type = data.type;
    let property = data.property;
    let sourceId = data.sourceId;
    let targetId = data.sourceId;
    return {
        'code': 200,
        'message': 'ok',
        'data':{
            id:11,
            name,
            type,
            property,
            sourceName:sourceId,
            targetName:targetId
        }
    }
}
export const getElementList = function (option) {
    let { pageNum,pageSize } = JSON.parse(option.body);
    const modelList = Mock.mock({
        'code': 200,
        'message': 'ok',
        'data': {
            'total': 100,
            'list|5': [{
                "ontologyElementId|+1":1,
                "ontologyElementName":'admin21214211111111111111111111111111111',
                "ontologyElementDescribe":'主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理',
                "ontologyElementImgUrl":'',
                "creatUserId":'admin1',
                "creatUserName":'admin1',
                "json":'主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理主要包含对国内外的军事武器装备的归纳整理',
                "status":0
            }],
            "pageNum":pageNum,
            "pageSize":pageSize
        }
    })
    return modelList;
}

const elementsNodes = [
    {   
        id: "1",
        label: "1",
        ontologyId: "12345",
    },
    {
        id: "2",
        label: "2",
        ontologyId: "123456"
    },
    {
        id: "3",
        label: "3",
        ontologyId: "1234567"
    },
    {
        id: "4",
        label: "4",
        ontologyId: "12345678"
    },
]
const elementsEdges = [
    {
        id: "1455",
        source: "1",
        target: "2",
        label: "关系1",
        edgetype: "oneway",
    },
    {
        id: "1465",
        source: "2",
        target: "1",
        label: "关系2",
        edgetype: "oneway",
    },
    {
        id: "1475",
        source: "1",
        target: "3",
        label: "关系3",
        edgetype: "oneway",
    },
]
export const  importElement = function(option) {
    let { ontologyElementIds,ontologyAllId } = JSON.parse(option.body);
    
    const modelList = Mock.mock({
        'code': 200,
        'message': 'ok',
        'data': {
            'nodes':elementsNodes,
            'edges':elementsEdges
        }
    })
    return modelList;
}

export const saveElement = {
    'code': 200,
    'message': 'ok',
    'data': null
}

export const allGraphData = {
    'code': 200,
    'message': 'ok',
    'data': {
        ontologyNodes: [{
                id: "214",
                label: "测试spo3",
                ontologyId: "12345",
            },
            {
                id: "216",
                label: "测试spo5",
                ontologyId: "123456"
            },
            {
                id: "254",
                label: "测试spo10",
                ontologyId: "1234567"
            },
            {
                id: "215",
                label: "测试spo4",
                ontologyId: "12345678"
            },
        ],
        ontologyEdges: [{
                id: "15",
                source: "214",
                target: "216",
                label: "装备着",
                edgetype: "oneway",
            },
            {
                id: "107",
                source: "215",
                target: "216",
                label: "装备着",
                edgetype: "oneway",
            },
            {
                id: "117",
                source: "254",
                target: "216",
                label: "第二种关系",
                edgetype: "oneway",
            },
            {
                id: "105",
                source: "214",
                target: "216",
                label: "装备着",
                edgetype: "oneway",
            },
            {
                id: "123",
                source: "214",
                target: "254",
                label: "关系1",
                edgetype: "oneway",
            },
            {
                id: "145",
                source: "216",
                target: "254",
                label: "关系2",
                edgetype: "oneway",
            },
        ]
    }
}